home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2001 December / pcwk12201b.iso / Wersje pelne i specjalne / Winamp 2.77 i 3.0beta / wasabi-sdk_beta1.exe / studio / attribs / attribute.h < prev    next >
C/C++ Source or Header  |  2001-10-08  |  4KB  |  183 lines

  1. /*
  2.  
  3.   Nullsoft WASABI Source File License
  4.  
  5.   Copyright 1999-2001 Nullsoft, Inc.
  6.  
  7.     This software is provided 'as-is', without any express or implied
  8.     warranty.  In no event will the authors be held liable for any damages
  9.     arising from the use of this software.
  10.  
  11.     Permission is granted to anyone to use this software for any purpose,
  12.     including commercial applications, and to alter it and redistribute it
  13.     freely, subject to the following restrictions:
  14.  
  15.     1. The origin of this software must not be misrepresented; you must not
  16.        claim that you wrote the original software. If you use this software
  17.        in a product, an acknowledgment in the product documentation would be
  18.        appreciated but is not required.
  19.     2. Altered source versions must be plainly marked as such, and must not be
  20.        misrepresented as being the original software.
  21.     3. This notice may not be removed or altered from any source distribution.
  22.  
  23.  
  24.   Brennan Underwood
  25.   brennan@nullsoft.com
  26.  
  27. */
  28.  
  29. #ifndef _ATTRIBUTE_H
  30. #define _ATTRIBUTE_H
  31.  
  32. #include "../common/std.h"
  33. #include "../common/dispatch.h"
  34. #include "../common/named.h"
  35.  
  36. class CfgItem;
  37. class CfgItemI;
  38.  
  39. // lowercase types are reserved for official Nullsoft use
  40. // uppercase are 3rd-party defined
  41. namespace AttributeType {
  42.   enum {
  43.     NONE = 0,
  44.     INT = 'int',
  45.     STRING = 'str',
  46.     BOOL = 'bool',
  47.   };
  48. };
  49.  
  50. class NOVTABLE Attribute : private Named {
  51. protected:
  52.   Attribute(const char *newname=NULL);
  53. public:
  54.   virtual ~Attribute();
  55.  
  56.   void setName(const char *newname);
  57.   const char *getAttributeName();
  58.   virtual int getAttributeType()=0;
  59.  
  60.   // the cfgitem this attribute is attached to (convenience fn)
  61.   void setCfgItem(CfgItemI *cfgitem);
  62.   CfgItem *getCfgItem();
  63.  
  64.   virtual int getDataLen()=0;
  65.   virtual int getData(void *ptr, int len)=0;
  66.   virtual int setData(void *ptr, int len)=0;
  67.  
  68. protected:
  69.   void _valueSet();
  70.  
  71. private:
  72.   CfgItemI *cfgitem;
  73. };
  74.  
  75. inline int _int_getValue(Attribute *attr, int def_val=0) {
  76.   ASSERT(attr->getAttributeType() == AttributeType::INT ||
  77.          attr->getAttributeType() == AttributeType::BOOL);
  78.   int ret;
  79.   if (!attr->getData(&ret, sizeof(ret))) return def_val;
  80.   return ret;
  81. }
  82.  
  83. inline int _int_setValue(Attribute *attr, int val) {
  84.   ASSERT(attr->getAttributeType() == AttributeType::INT ||
  85.          attr->getAttributeType() == AttributeType::BOOL);
  86.   return attr->setData(&val, sizeof(int));
  87. }
  88.  
  89.  
  90. #if 0//CUT
  91. class NOVTABLE AttributeInt : public Attribute {
  92. public:
  93.   int getValue();
  94.   int setValue(int val);
  95. //  int getRange(int *lower, int *upper, int *step);
  96.  
  97.   enum {
  98.     GETVALUE = 10000,
  99.     SETVALUE = 10010,
  100.   };
  101. };
  102.  
  103. class AttributeString : public Attribute {
  104. public:
  105.   const char *getValue();
  106.   const char *setValue(const char *val);
  107.  
  108.   enum {
  109.     GETVALUE = 11000,
  110.     SETVALUE = 11010,
  111.   };
  112. };
  113.  
  114. inline const char *Attribute::getAttributeName() {
  115.   return _call(GETATTRIBUTENAME, "");
  116. }
  117.  
  118. inline int Attribute::getAttributeType() {
  119.   return _call(GETATTRIBUTETYPE, -1);
  120. }
  121.  
  122. inline int Attribute::getPermissions() {
  123.   return _call(GETPERMISSIONS, 0);
  124. }
  125.  
  126. inline CfgItem *Attribute::getCfgItem() {
  127.   return _call(GETCFGITEM, (CfgItem*)0);
  128. }
  129.  
  130. inline int Attribute::getRawDataLen() {
  131.   return _call(GETRAWDATALEN, 0);
  132. }
  133.  
  134. inline int Attribute::getRawData(void *ptr, int maxlen) {
  135.   return _call(GETRAWDATA, 0, ptr, maxlen);
  136. }
  137.  
  138. inline int AttributeInt::getValue() {
  139.   return _call(GETVALUE, 0);
  140. }
  141.  
  142. inline int AttributeInt::setValue(int val) {
  143.   return _call(SETVALUE, 0, val);
  144. }
  145.  
  146. inline const char *AttributeString::getValue() {
  147.   return _call(GETVALUE, (const char *)0);
  148. }
  149.  
  150. inline const char *AttributeString::setValue(const char *val) {
  151.   return _call(SETVALUE, (const char *)0, val);
  152. }
  153. #endif
  154.  
  155. #define ATTR_PERM_READ    1
  156. #define ATTR_PERM_WRITE    2
  157.  
  158. #define ATTR_PERM_ALL    (~0)
  159.  
  160. // render hints for getRenderHint
  161. enum {
  162.   ATTR_RENDER_HINT_INT_CHECKMARK
  163. };
  164.  
  165. #if 0
  166. // an AttributeInt adds these methods
  167. class NOVTABLE AttributeInt {
  168. public:
  169.   virtual int getValue()=0;
  170.   virtual int setValue(int val)=0;
  171.   virtual int getRange(int *lower, int *upper, int *step)=0;
  172. //  virtual int setRange(int lower, int upper, int step)=0;
  173. };
  174.  
  175. class NOVTABLE AttributeString {
  176. public:
  177.   virtual const char *getValue()=0;
  178.   virtual const char *setValue(const char *val)=0;
  179. };
  180. #endif
  181.  
  182. #endif
  183.